package mainillnessname;

import java.util.ArrayList;

import com.example.animaldoctor03.R;

import commonClass.ADAQueryAllDiseaseInfoByAnimalDiseaseCategorieIDAction;
import commonClass.FunctionDispatcher;
import commonClass.RemoteActionsName;
import commonClass.FunctionDispatcher.IRequestCompeletListener;
import Modle.disease.AnimalDiseaseCategorie;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import Modle.disease.Disease;
public class IllnessNameDetails extends Activity {

	private ListView listofIND = null;
	private String IDofIND = "";
	private ArrayList<Object> resultListofIND = null;

	private void CSHofIND() {

		setContentView(R.layout.illnessnamedetails);
		listofIND = (ListView) findViewById(R.id.listofIND);
	}

	private void getinformationofIND() {

		Intent intentofIND = getIntent();
		Bundle bundleofIND = intentofIND.getExtras();
		AnimalDiseaseCategorie informationofIND = (AnimalDiseaseCategorie) bundleofIND
				.get("shuju");
		IDofIND = informationofIND.getAnimalDiseaseCategorieID();

	}

	private ArrayList<Object> assemblyofIND() {

		getinformationofIND();
		ArrayList<Object> list = new ArrayList<Object>();

		list.add(IDofIND);
		return list;
	}

	private void bindingofIND(final ArrayList<Object> list) {
		 try{
		System.out.print("0000" + list.size());
		String [] resultofIND = new String[list.size()];
		for(int i = 0 ; i < list.size() ; i++){
			
			resultofIND [i] = ((Disease)list.get(i)).getDiseaseChineseName();
		}
		if(list.size() > 0){
		
		ArrayAdapter<String> arrofIND = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1 , resultofIND);
		listofIND.setAdapter(arrofIND);
		}
		else{
			String [] text = {"shibai"};
			ArrayAdapter<String> arrofIND2 = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1 , text);
			listofIND.setAdapter(arrofIND2);
			}
			
	
		
		listofIND.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
			Disease shujuofIND = (Disease)list.get(position);
				
				Bundle bundleofIND = new Bundle();
				bundleofIND.putSerializable("shuju", shujuofIND);
				Intent intentofIND = new Intent(IllnessNameDetails.this , PossibleZZ.class);
				intentofIND.putExtras(bundleofIND);
				startActivity(intentofIND);
				finish();
			}
		});
		 }catch(NullPointerException e){
			 Builder builderofIND = new AlertDialog.Builder(IllnessNameDetails.this);
			 builderofIND.setMessage("无数据,请用其他功能");
			 builderofIND.create().show();
		 }

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		CSHofIND();
		assemblyofIND();
		ArrayList<Object> parasListofIND= assemblyofIND();
		final ArrayList<Object> resultListTofIND = null;
		ADAQueryAllDiseaseInfoByAnimalDiseaseCategorieIDAction iActionofIND = new ADAQueryAllDiseaseInfoByAnimalDiseaseCategorieIDAction();
		FunctionDispatcher functionDispacherofIND = new FunctionDispatcher();
	try{	
		functionDispacherofIND.exceute(RemoteActionsName.QueryAllDiseaseInfoByAnimalDiseaseCategorieIDAction, parasListofIND, iActionofIND, new IRequestCompeletListener() {

			@Override
			public void doCompelet(ArrayList<Object> resultList) {
				// TODO Auto-generated method stub
		
				IllnessNameDetails.this.resultListofIND = resultList;
				
				Log.v("000000", "daozhele");
		
				bindingofIND(resultList);
				
			}
		},this);
	}catch(NullPointerException e){
		
		Builder builderofINDf = new AlertDialog.Builder(IllnessNameDetails.this);
		builderofINDf.setMessage("无返回值,请用其他功能");
		builderofINDf.create().show();
	}

	}

}
